//
//  MyCustomTableVeiwCell.m
//  ICard
//
//  Created by fanshao on 11-2-27.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "MyCustomTableVeiwCell.h"


@implementation MyCustomTableVeiwCell

@synthesize primaryTextField;
@synthesize deleteButton;
@synthesize myImageView;

@synthesize deleteDelegate;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code.
		UITextField *tempTextfield = [[UITextField alloc] init];
		//[tempTextfield becomeFirstResponder];
		self.primaryTextField = tempTextfield;
		[tempTextfield setBorderStyle:UITextBorderStyleRoundedRect];
		[tempTextfield release];
		[self.contentView addSubview:self.primaryTextField];
		
		UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
		self.deleteButton = tempButton;
		[self.contentView addSubview:self.deleteButton];
		[self.deleteButton setImage:[UIImage imageNamed:@"minus.png"] forState:UIControlStateNormal];
		[self.deleteButton addTarget:self action:@selector(deleteContact:) forControlEvents:UIControlEventTouchUpInside];
		
		myImageView = [[UIImageView alloc]init];
		[self.contentView addSubview:myImageView];
		[myImageView setImage:[UIImage imageNamed:@"im.png"]];
		
    }
    return self;
}

/*- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
	if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
		// Initialization code
		UITextField *tempTextfield = [[UITextField alloc] init];
		[tempTextfield becomeFirstResponder];
		self.primaryTextField = tempTextfield;
		[tempTextfield release];
		[self.contentView addSubview:self.primaryTextField];
		
		UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
		self.deleteButton = tempButton;
		[self.contentView addSubview:self.deleteButton];
		
		myImageView = [[UIImageView alloc]init];
		[self.contentView addSubview:myImageView];
		
	}
	return self;
}*/
- (void)layoutSubviews {
	[super layoutSubviews];
	CGRect contentRect = self.contentView.bounds;
	CGFloat boundsX = contentRect.origin.x;
	CGRect frame;
	frame= CGRectMake(boundsX+0 ,0, 50, 50);
	self.myImageView.frame = frame;
	
	frame= CGRectMake(boundsX+60 ,5, 200, 25);
	self.primaryTextField.frame = frame;
	
	frame= CGRectMake(boundsX+270 ,0, 50, 50);
	self.deleteButton.frame = frame;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state.
}


- (IBAction)deleteContact:(id)sender{
	[deleteDelegate deleteCell:self];
}
- (void)dealloc {
    [super dealloc];
}


@end
